package lang.enumeration.safe;

import java.util.HashMap;
import java.util.Map;

public final class WordClass {

	private static final Map<String, WordClass> cache = new HashMap<String, WordClass>();

	public static final WordClass noun = new WordClass("noun");
	public static final WordClass NOUN = noun;

	public static final WordClass pronoun = new WordClass("pronoun");
	public static final WordClass PRONOUN = pronoun;

	public static final WordClass determiner = new WordClass("determiner");
	public static final WordClass DETERMINER = determiner;
	
	public static final WordClass adjective = new WordClass("adjective");
	public static final WordClass ADJECTIVE = adjective;

	public static final WordClass verb = new WordClass("verb");
	public static final WordClass VERB = verb;

	public static final WordClass adverb = new WordClass("adverb");
	public static final WordClass ADVERB = adverb;

	public static final WordClass preposition = new WordClass("preposition");
	public static final WordClass PREPOSITION = preposition;

	public static final WordClass conjunction = new WordClass("conjunction");
	public static final WordClass CONJUNCTION = conjunction;

	public static final WordClass interjection = new WordClass("interjection");
	public static final WordClass INTERJECTION = interjection;

	public static WordClass getByName(String name) {
		WordClass wordClass = cache.get(name);
		if (wordClass == null) {
			throw new IllegalArgumentException("没有称为 " + name + " 的词性，请在 " + cache.keySet() + " 中选一个");
		}
		return cache.get(name);
	}

	private String name;

	private WordClass(String name) {
		this.name = name;
		cache.put(name, this);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return name;
	}
	
	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		return super.equals(obj);
	}
}
